package controller

import (
	services "hft/Http/Services"
	utils "hft/Http/Utils"
	"hft/tools"

	"github.com/gin-gonic/gin"
)

// 后台登录模式
type BackEnter struct{}

func (b *BackEnter) EnterChildAccount(c *gin.Context) {

	username, exist := c.GetQuery("username")

	if !exist {
		utils.FailWithMessage("无效的登录", c)
		c.Abort()
		return
	}

	if claims, err := tools.GetClaims(c); err != nil {
		utils.FailWithMessage("授权失败", c)
	} else {
		if token, err := services.BackEnterService.EnterChildAccount(username, &claims.BaseClaims); err != nil {
			utils.FailWithMessage(err.Error(), c)
		} else {
			utils.OkWithData(gin.H{
				"access_token": token, //进入的access_token
			}, c)
		}
	}

}

var BackEnterController = new(BackEnter)
